import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CommonLib {

    public static String getCurrentTime() {
        try {
            Calendar ca = Calendar.getInstance();
            int year = ca.get(Calendar.YEAR);
            int month = ca.get(Calendar.MONTH);
            int day = ca.get(Calendar.DATE);
            int minute = ca.get(Calendar.MINUTE);
            int hour = ca.get(Calendar.HOUR);
            int second = ca.get(Calendar.SECOND);
            String currentTime = (String.valueOf(year) + "-" + String.valueOf(month + 1) + "-"
                    + String.valueOf(day) + "-" + String.valueOf(hour) + "-"
                    + String.valueOf(minute) + "-" + String.valueOf(second));
            return currentTime;
        } catch (Exception e) {
            return "00000000";
        }
    }
    public static String dateToStrLong(Date dateDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(dateDate);
		return dateString;
	}
    public static String getDifferenceTime(String lastTime,String latestTime) throws ParseException{
    	SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date begin = dfs.parse(lastTime);
			Date end = dfs.parse(latestTime);
			long between=(end.getTime()-begin.getTime())/1000;
			//除以1000是为了转换成秒
			long day1=between/(24*3600);
			long hour1=between%(24*3600)/3600;
			long minute1=between%3600/60;
			long second1=between%60/60;
			System.out.println(""+day1+"天"+hour1+"小时"+minute1+"分"+second1+"秒");
			String difTime = ""+day1+"天"+hour1+"小时"+minute1+"分"+second1+"秒";
			return difTime;
	}
    
    public static void main(String[] args) throws ParseException {
		String xx = dateToStrLong(new Date());
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		for (int i = 0; i < 100000; i++) {
			
		}
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		System.out.println("'''''''''''''''''''''''''''''''''''''");
		String yy = dateToStrLong(new Date());
		getDifferenceTime(xx, yy);
	}
}

